home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9363 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  5.8 KB

  1. Path: goanna.cs.rmit.EDU.AU!not-for-mail
  2. From: ok@goanna.cs.rmit.EDU.AU (Richard A. O'Keefe)
  3. Newsgroups: comp.lang.ada,comp.lang.c++,comp.lang.c,comp.lang.modula3,comp.lang.modula2
  4. Subject: Re: Hungarian notation - whoops!
  5. Date: 1 Mar 1996 20:57:12 +1100
  6. Organization: Comp Sci, RMIT, Melbourne, Australia
  7. Message-ID: <4h6hlo$hqu@goanna.cs.rmit.EDU.AU>
  8. References: <30C40F77.53B5@swsbbs.com> <4fms62$c0p@goanna.cs.rmit.EDU.AU> <4ft1ruINN6dr@keats.ugrad.cs.ubc.ca> <4g9255$74s@goanna.cs.rmit.EDU.AU> <4gip1iINNjd@keats.ugrad.cs.ubc.ca>
  9. NNTP-Posting-Host: goanna.cs.rmit.edu.au
  10. X-Newsreader: NN version 6.5.0 #0 (NOV)
  11.  
  12. > >I wrote:
  13. > >    But the fact that abs(x) may deliver a negative
  14. > >    number is something I have to live with the whole time.
  15.  
  16. c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku) writes:
  17. >It does so for the largest negative value. This is documented. Unfortunately,
  18. >as you claim, you do have to check that yourself. And of course, to know what
  19. >the largest negative value is, you can use the standard #defined manifest
  20. >constants. It's not like abs() returns a negative value for any old random
  21. >input. The fact of the matter is that the additive inverse of the largest
  22. >negative value under two's complement simply can't be represented in a two's
  23. >complement word of the same size, yet the return value from abs() is a signed
  24. >quantity. Shrug.
  25.  
  26. "shrug"?
  27. Every program I write either (a) gets significantly more complex, making it
  28. more costly to write, inspect, and debug, or (b) incurs risk of error, and
  29. you say "shrug"?
  30.  
  31. Why should I read anything else you write, if our attitudes are so different?
  32.  
  33. As for the rest, which I did read, Kazimir keeps on trying to instruct me
  34. about C.  But I ****know**** about C.  I know a LOT about C.  I don't need
  35. to be instructed about it.  My problem isn't ignorance, it's dislike.
  36.  
  37. >For _one_ legal input. :)
  38.  
  39. One legal input is one LEGAL input.
  40.  
  41. I am concerned about writing reliable maintainable software at affordable
  42. cost.  I am only interested in hardware, languages, compilers, and so on
  43. as a means to that end.  I am NOT interested in wasting my time fighting
  44. around rough edges that do not serve MY ends.
  45.  
  46. >I didn't say that it wasn't. But the Ada compiler has to also do a little
  47. >``code explosion'' to ensure the same portability as your C with programmer
  48. >inserted masking.
  49.  
  50. Yes, but the COMPILER does it!  _I_ don't have to design, code, inspect, test,
  51. debug, document, maintain, &c the code that the compiler generates.  I don't
  52. _care_ what the compiler does.  What I care about is that my source code is
  53. as clean and straightforward as possible.  Surely I cannot be alone in this,
  54. or Ada would not exist.
  55.  
  56. > >Overflows aren't the problem.  Restricted machine arithmetic is the problem.
  57.  
  58. >Not much you can do about the machine, as a programmer and  supporting
  59. >multi-precision arithmetic in any language imposes a lot of overhead and code
  60. >explosion.
  61.  
  62. (a) I didn't ask for multi-precision arithmetic.
  63.     I meant "restricted" in an entirely different sense.
  64. (b) It is simply false that supporting multi-precision arithmetic imposes
  65.     a LOT of overhead or code explosion.  Bad implementations may have
  66.     such overheads, but it is bad implementation that imposes them, not
  67.     high precision arithmetic.  If you mean that supporting numbers up to
  68.     18 decimal digits (as required by the COBOL standard) on a 32-bit-only
  69.     machine is slower than using confining yourself to what the machine can
  70.     do in a single cycle, then yes, but so what?  What counts is overhead
  71.     *relative to other ways of getting RIGHT ANSWERS*.  (Note:  on a number
  72.     of modern machines a subroutine call is a single instruction, so if we
  73.     compare
  74.     load r1, X
  75.     load r2, Y
  76.     add r1, r1, r2
  77.     store r1, Z
  78.     with
  79.     load r1, @X
  80.     load r2, @Y
  81.     call,delayed add_64
  82.     load r3, @Z
  83.     we find no difference whatsoever in the code size.  Yes, it's slower,
  84.     but it gets the right answer.
  85.  
  86.  
  87. Look, let's drop this.  As far as I was concerned, the real issue is
  88. that
  89.  
  90.     hardware and software exist to help us solve real-world problems
  91.     they should be co-designed to minimise the cost of reliable
  92.     correct computing.
  93.  
  94. There is no need to educate me about C or present CPUs.  C was, and in its
  95. essence still is, a language which is designed to make it easy for an
  96. expert programmer to control a machine.  There is certainly room for such
  97. languages, even assembly code has its niche.  My complaint is not about
  98. 2s-complement as such, it is about programming languages that let it show
  99. through in the form of giving wrong answers.  It is NOT my job to make my
  100. program complicated to compensate for weak compilers.  That is my complaint.
  101.  
  102. >BTW do you have some sort of specific gripe with two's complement
  103. >representations of integer arithmetic?
  104.  
  105. I already explained my gripe in detail.  The "extra" value may simplify
  106. life for computer architects.  But it _doesn't_ simplify life for
  107. programmers.  Example:
  108.  
  109.     int like_atoi(char *p) {
  110.         int sign = 1;
  111.         int n = 0;
  112.  
  113.         if (*p == '+') p++; else    
  114.         if (*p == '-') p++, sign = -1;
  115.  
  116.         while (isdigit(*p)) n = n*10 + (*p++ - '0');
  117.         return n*sign;
  118.     }
  119.     
  120. If you are on a machine where signed arithmetic overflows are signalled
  121. (MIPS), why does this have to be written
  122.  
  123.     int like_atoi(char *p) {
  124.         int sign = -1;
  125.         int n = 0;
  126.  
  127.         if (*p == '+') p++; else
  128.         if (*p == '-') p++, sign = 1;
  129.  
  130.         while (isdigit(*p)) n = n*10 - (*p++ - '0');
  131.         return n*sign;
  132.     }
  133.  
  134. instead?  In sign-and-magnitude or ones-complement arithmetic, both versions
  135. do exactly the same thing.  In overflow-checked twos-complement, you have to
  136. use the second version.  I've encountered quite a number of programs that
  137. get it wrong.  You have to be aware of that extra value the whole time, and
  138. it doesn't solve any application problems.
  139.  
  140. -- 
  141. Election time; but how to get Labor _out_ without letting Liberal _in_?
  142. Richard A. O'Keefe; http://www.cs.rmit.edu.au/~ok; RMIT Comp.Sci.
  143.